/**
 * Auto gen via dbpojo-gen.
 */
package com.us.usws.service.ro.impl;

import java.util.List;

import com.us.usws.cache.UserCache;
import com.us.usws.common.SiteConstants;
import com.us.usws.dao.BaseDictDAO;
import com.us.usws.dao.BaseVideoCatDAO;
import com.us.usws.model.domain.base.BaseDict;
import com.us.usws.model.domain.base.BaseVideoCat;
import com.us.usws.service.ro.BaseDictROService;
import com.us.usws.support.ext.CacheManager;
import com.us.usws.support.uitls.DataPageUtil;

/**
 * Service RO impl class
 * @author robot
 */
public class BaseDictROServiceImpl implements BaseDictROService {

	/**
	 * DAO instance
	 */
	private BaseDictDAO dao = new BaseDictDAO();
	
	private BaseVideoCatDAO videoCatDao = new BaseVideoCatDAO();

	/**
	 * Get Count.
	 */
	@Override
	public int getTotalCount() {
		return dao.getTotalCount();
	}

	/**
	 * Get all list.
	 */
	@Override
	public List<BaseDict> getAllBaseDicts() {
		return dao.getAllBaseDicts();
	}
	
	public void loadBaseDictsByPage(DataPageUtil<BaseDict> dataPageUtil) {
		dao.loadBaseDictsByPage(dataPageUtil);
		List<BaseDict> rs = dataPageUtil.getResult();
		if(rs != null && rs.size() > 0) {
			UserCache userCache = CacheManager.getUserCache();
			for(BaseDict dt:rs) {
				dt.setCreateUserName(userCache.getUserName(dt.getCreateByUid()));
			}
		}
	}
	
	public List<BaseDict> getDictByDomain(String domain) {
		List<BaseDict> dts = CacheManager.getDictCache().getDicts(domain);
		UserCache userCache = CacheManager.getUserCache();
		for(BaseDict dt:dts) {
			dt.setCreateUserName(userCache.getUserName(dt.getCreateByUid()));
			if(SiteConstants.DICT_DOMAIN_VIDEO_TYPE.equals(domain)) {
				List<BaseVideoCat> bvcs = videoCatDao.getRalateCatsByVideoType(dt.getSepId());
				dt.setVideoCats(bvcs);
			}
		}
		return dts;
	}

	/**
	 * Get all list by pagination.
	 */
	@Override
	public List<BaseDict> getBaseDicts(int start, int end) {
		return dao.getBaseDicts(start, end);
	}

	/**
	 * Get BaseDict by primary key.
	 */
	@Override
	public BaseDict getBaseDict(String uid) {
		BaseDict b = dao.getBaseDict(uid);
		return b;
	}
}